import React from "react";
import PropTypes from "prop-types";
import { UserProfile } from "@/components/proptypes";

export default function UserOrgUnit({ orgunits, user, ...props }) {
  return (
    <div {...props}>
      {orgunits
        .filter(orgunit => user.orgunit_id === orgunit.value)
        .map(orgunit => (
          <span>{orgunit.name}</span>
        ))}
    </div>
  );
}

UserOrgUnit.propTypes = {
  orgunits: PropTypes.arrayOf(
    PropTypes.shape({
      value: PropTypes.string.isRequired,
      name: PropTypes.string,
    })
  ),
  user: UserProfile.isRequired,
};

UserOrgUnit.defaultProps = {
  orgunits: [],
};
